<template>
  <div>
  <el-row style="height: 840px;"  >
    <!--搜索框组件-->
    <search-bar @onSearch="searchDoctor" ref="searchBar"/>

    <el-tooltip effect="dark" placement="right"
                v-for="item in doctors.slice((currentPage-1)*pageSize,currentPage*pageSize)"
                :key="item.id"
                @click.native="goToWaitingQueue(item.drId)">
      <p slot="content"
         style="font-size: 14px;margin-bottom: 6px;">{{item.titleName}}</p>
      <p slot="content"
         style="font-size: 13px;margin-bottom: 6px">
        <span>{{item.realName}}</span> /
        <span>{{item.hospitalName}}</span>

      </p>
      <p slot="content" style="width: 300px"
         class="perInfo">{{item.perInfo}}</p>
      <el-card
          class="doctor"
          bodyStyle="padding:10px" shadow="hover">

        <div class="cover">
          <img :src="avatar.url" alt="封面">
        </div>
        <div class="info">
          <div class="title">
            <a href="">{{item.departmentName}}</a>
          </div>
        </div>
        <div class="realName">{{item.realName}}
          <span>{{showStatus(item)}}</span></div>

      </el-card>
    </el-tooltip>
  </el-row>
  <el-row>
    <el-pagination
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="doctors.length">
    </el-pagination>
  </el-row>
  </div>


</template>

<script>
import SearchBar from './doctorSearchBar'
export default {
  name: "doctors",
  components: {
    SearchBar
  },
  data() {
    return{
      avatar: {url:require("../../../assets/images/cover.jpg")},
      doctors: [
        {
          drId: 0,
          hospitalId: 0,
          departmentId: 0,
          realName: '',
          title: 0,
          perInfo: '',
          doctorStatus: '',
          userId: 0,
          hospitalName: '',
          titleName: '',
          statusName: '',
          departmentName: ''
        }
      ],
      currentPage: 1,
      pageSize: 16
    }
  },created(){

  },mounted: function (){
    this.getDoctorInfo();
  },computed:{


}
  ,methods: {
    getDoctorInfo(){
      const self = this;
      let body = {
        method: 'all',
        params: {
        }
      }
      this.$axios
          .post('api/doctor/findDoctorInfo',body)
          .then(res=>{

              self.doctors = res.data.data;

              self.doctors.forEach((item,index,arr)=>{
                item.perInfo = !item.perInfo ? '暂无简介':item.perInfo;
              })

          }).catch(err => {console.log(err)})
    },
    goToWaitingQueue(id){
      const self = this;
      localStorage.setItem("visitedDoctorId",id);

      self.$router.push('/doctorInfo/waitingQueue')
    },
    searchDoctor(){
      const self = this;
      let keywords = self.$refs.searchBar.keywords;
      let reqBody= {
        method: 'doctorOrHospital',
        params : {
          name : keywords
        }
      }

      this.$axios.post('api/doctor/findDoctorInfo',reqBody)
          .then(res => {
            self.doctors = res.data.data;
            self.$refs.searchBar.keywords = " ";
          }).catch(err => {console.error(err)})

    },
    handleCurrentChange: function (currentPage) {
      this.currentPage = currentPage
      console.log(this.currentPage)
    },showStatus: function (val) {
      let status = val.statusName;
      //TODO 替换显示的状态


      return status;
    }

  }
}
</script>

<style scoped>

  .cover {
    width: 115px;
    height: 172px;
    margin-bottom: 7px;
    overflow: hidden;
    cursor: pointer;
  }

  img {
    width: 115px;
    height: 172px;
    /*margin: 0 auto;*/
  }
  .title {
    font-size: 14px;
    text-align: left;
  }

  .realName {
    color: #333;
    width: 102px;
    font-size: 13px;
    margin-bottom: 6px;
    text-align: left;
  }

  .perInfo {
    display: block;
    line-height: 17px;
  }

  a {
    text-decoration: none;
  }

  a:link, a:visited, a:focus {
    color: #3377aa;
  }
  .el-pagination{
    margin: 0 auto; text-align: center;
  }

  .doctor{
    width: 135px;
    margin-bottom: 20px;
    height: 233px;
    float: left;
    margin-right: 15px;
  }
</style>